import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';

class ProgressBar extends StatelessWidget {
  double percent;
  final String cur;
  final String totle;
  final String name;
  ProgressBar(
      {Key? key,
      required this.percent,
      required this.cur,
      required this.totle,
      required this.name})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return _progressBar();
  }

  // 进度条
  Widget _progressBar() {
    Widget progress = ClipRRect(
      // 边界半径（`borderRadius`）属性，圆角的边界半径。
      borderRadius: BorderRadius.all(Radius.circular(10.0)),
      child: LinearProgressIndicator(
        value: percent,
        minHeight: 14,
        backgroundColor: Color(0xff362B76),
        valueColor: AlwaysStoppedAnimation<Color>(Color(0xffFFED4A)),
      ),
    );

    percent =
        (Decimal.parse(percent.toString()) * Decimal.parse('100')).toDouble();
    Widget container = Container(
      padding: EdgeInsets.only(left: 20, right: 20),
      child: Column(
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Expanded(
                  child: Column(
                children: [
                  Container(
                    margin: EdgeInsets.only(bottom: 8),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          name,
                          style: TextStyle(color: Colors.white),
                        ),
                        Container(
                          child: Row(
                            children: [
                              Text(
                                cur,
                                style: TextStyle(color: Colors.white),
                              ),
                              Text(
                                totle,
                                style: TextStyle(color: Color(0xffFFED4A)),
                              )
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                  progress
                ],
              )),
              Container(
                margin: EdgeInsets.only(left: 8),
                child: Text(
                  '${percent}%',
                  style: TextStyle(color: Colors.white),
                ),
              )
            ],
          )
        ],
      ),
    );
    return container;
  }
}
